package com.mjlf.nio;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.*;

/**
 * @ClassName ChannelTest
 * @auther mjlf
 * @Date 2019/9/10 17:34
 * @Description TODO
 */
public class ChannelTest {
    public static void main(String[] args) throws IOException {
        ReadableByteChannel read = Channels.newChannel(System.in);
        WritableByteChannel write = Channels.newChannel(System.out);
        ByteBuffer byteBuffer = ByteBuffer.allocate(16 * 1024);

        while((read.read(byteBuffer) != -1)){
            byteBuffer.flip();
            write.write(byteBuffer);
            byteBuffer.clear();
        }

        read.close();
        write.close();
    }
}
